package com.bt.att.model;

import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;

/**
 * Enumeration for property data type.
 *
 * @author Zakir Magdum
 */
public enum ChartType {

    CallsByPerson("Number of calls by person"),
    DurationByPerson("Call duration by person"),
    TextsByPerson("Number of Texts by Person"),
    CallsByTime("Number of calls by time"),
    DurationByTime("Call duration by time"),
    TextsByTime("Number of Texts by time");

    /**
     * The value.
     */
    private String value;

    /**
     * The map.
     */
    private static Map<String, ChartType> map;

    /**
     * Instantiates a new property data type.
     *
     * @param platformName the platform name
     */
    private ChartType(String platformName) {
        this.value = platformName;
        addToMap(this);
    }

    /**
     * Adds the to map.
     *
     * @param type the type
     */
    private static synchronized void addToMap(ChartType type) {
        if (map == null) {
            map = new HashMap<String, ChartType>();
        }
        map.put(type.toString(), type);
    }

    /* (non-Javadoc)
     * @see java.lang.Enum#toString()
     */

    @Override
    public String toString() {
        return value;
    }

    /**
     * From string.
     *
     * @param value the value
     * @return the property data type
     */
    public static ChartType fromString(String value) {
        ChartType type = map.get(value);
        if (type == null) {
            throw new RuntimeException(MessageFormat.format("ChartType not found for {0}", value));
        }
        return type;
    }

    public static Map<String, ChartType> chartTypeMap() {
        return map;
    }
}
